home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cug232 / apndx1 < prev    next >
Text File  |  1987-06-17  |  55KB  |  1,450 lines

  1. .so macros
  2. .nh
  3. .ds CF
  4. .ds CH
  5. .ps +0.2i
  6. .nr PO +0.2i
  7. .Nm Object
  8. .PP
  9. The class \fBObject\fP is a superclass of all classes in the system, and is
  10. used to provide a consistent basic functionality and default behavior.
  11. Many methods in class \fBObject\fP are overridden in subclasses.
  12. .SH
  13. Responds to
  14. .Rs ==
  15. Return true if receiver and argument are the
  16. same object, false otherwise.
  17. .Rs ~~
  18. Inverse of ==.
  19. .Rs asString
  20. Return a string representation of the receiver,
  21. by default this is the same as \fIprintString\fP, although one or the
  22. other is redefined in many subclasses.
  23. .Rs asSymbol
  24. Return a symbol representing the receiver.
  25. .Rs class
  26. Return object representing the class of the receiver.
  27. .Rs copy
  28. Return shallowCopy of receiver.
  29. Many subclasses redefine shallowCopy.
  30. .Rs deepCopy
  31. Return the receiver.  This method is redefined in many sub\%classes.
  32. .Rs do: d
  33. The argument must be a one argument block.
  34. Execute the block on every element of the receiver collection.
  35. Elements in the receiver collection are listed using \fIfirst\fP and \fInext\fP
  36. (below), so the default behavior is merely to execute the block using the
  37. receiver as argument.
  38. .Rs error:
  39. Argument must be a String.  Print argument string as error message.
  40. Return \fBnil\fP.
  41. .Rs first n
  42. Return first item in sequence, which is by default simply the receiver.
  43. See \fInext\fP, below.
  44. .Rs isKindOf:
  45. Argument must be a \fBClass\fP.  Return true if class of receiver, or any
  46. superclass thereof, is the same as argument.
  47. .Rs isMemberOf:
  48. Argument must be a \fBClass\fP.  Return true if receiver is instance of
  49. argument class.
  50. .Rs isNil
  51. Test whether receiver is object \fBnil\fP.
  52. .Rs next n
  53. Return next item in sequence, which is by default \fBnil\fP.  This message is
  54. redefined in classes which represent sequences, such as \fBArray\fP
  55. or \fBDictionary\fP.
  56. .Rs notNil
  57. Test if receiver is not object \fBnil\fP.
  58. .Rs print
  59. Display print image of receiver on the standard output.
  60. .Rs printString
  61. Return a string representation of receiver.
  62. Objects which do not redefine printString, and which therefore do not have
  63. a printable representation, return their class name as a string.
  64. .Rs respondsTo:
  65. Argument must be a symbol.  Return true if receiver will respond to
  66. the indicated message.
  67. .Rs shallowCopy
  68. Return the receiver.  This method is redefined in many sub\%classes.
  69. .Ex
  70. 7 ~~ 7.0    True
  71. 7 asSymbol    #7
  72. 7 class    Integer
  73. 7 copy    7
  74. 7 isKindOf: Number    True
  75. 7 isMemberOf: Number    False
  76. 7 isNil    False
  77. 7 respondsTo: #+    True
  78. .Nm Object UndefinedObject
  79. .PP
  80. The pseudo variable \fBnil\fP is an instance (usually the only instance) of the
  81. class \fBUndefinedObject\fP.  \fBnil\fP is used to represent undefined values,
  82. and is
  83. also typically returned in error situations.  \fBnil\fP is also used as a terminator
  84. in sequences, as for example in response to the message \fInext\fP when there are
  85. no further elements in a sequence.
  86. .SH
  87. Responds to
  88. .Rs isNil r
  89. Overrides method found in Object.  Return true.
  90. .Rs notNil r
  91. Overrides method found in Object.  Return false.
  92. .Rs printString r
  93. Return 'nil'.
  94. .Ex
  95. nil isNil    True
  96. .Nm Object Symbol
  97. .PP
  98. Instances of the class \fBSymbol\fP are created either by their literal
  99. representation, which is a pound sign followed by a string of nonspace
  100. characters (for example #aSymbol ),
  101. or by the message \fIasSymbol\fP being passed to an object.
  102. Symbols cannot be created using \fInew\fP.  Symbols are guaranteed to have
  103. unique representations; that is, two symbols representing the same
  104. characters will always test equal to each other.  Inside of literal
  105. arrays, the leading pound signs on symbols can be eliminated, for example:
  106. #(these are symbols).
  107. .SH
  108. Responds to
  109. .Rs == r
  110. Return true if the two symbols represent the same characters,
  111. false otherwise.
  112. .Rs asString r
  113. Return a String representation of the symbol without the leading pound
  114. sign.
  115. .Rs printString r
  116. Return a String representation of the symbol, including the leading pound
  117. sign.
  118. .Ex
  119. #abc == #abc    True
  120. #abc == #ABC    False
  121. #abc ~~ #ABC    True
  122. #abc printString    #abc
  123. \&'abc' asSymbol    #abc
  124. .Nm Object Boolean
  125. .PP
  126. The class \fBBoolean\fP provides protocol for manipulating true and false values.
  127. The pseudo variables \fBtrue\fP and \fBfalse\fP are instances of the subclasses of
  128. \fBBoolean\fP; \fBTrue\fP and \fBFalse\fP, respectively.
  129. The subclasses \fBTrue\fP and \fBFalse\fP, in combination with blocks, are used to
  130. implement conditional control structures.  Note, however, that the
  131. bytecodes may optimize conditional tests by generating
  132. code in-line, rather than using message passing.
  133. Note that bit-wise boolean operations are provided by class \fBInteger\fP.
  134. .SH
  135. Responds To
  136. .Rs &
  137. The argument must be a boolean.  Return the logical conjunction (and)
  138. of the two values.
  139. .Rs |
  140. The argument must be a boolean.  Return the logical disjunction (or)
  141. of the two values.
  142. .Rs and:
  143. The argument must be a block.  Return the logical conjunction (and)
  144. of the two values.  If the receiver is false the second argument is not
  145. used, otherwise the result is the value yielded in evaluating the argument
  146. block.
  147. .Rs or:
  148. The argument must be a block.  Return the logical disjunction (or)
  149. of the two values.  If the receiver is true the second argument is not
  150. used, otherwise the result is the value yielded in evaluating the argument
  151. block.
  152. .Rs eqv:
  153. The argument must be a boolean.  Return the logical equivalence (eqv)
  154. of the two values.
  155. .Rs xor:
  156. The argument must be a boolean.  Return the logical exclusive or (xor)
  157. of the two values.
  158. .Ex
  159. (1 > 3) & (2 < 4)    False
  160. (1 > 3) | (2 < 4)    True
  161. (1 > 3) and: [2 < 4]    False
  162. .Nm Object Boolean True
  163. .PP
  164. The pseudo variable \fBtrue\fP is an instance (usually the only instance) of
  165. the class \fBTrue\fP.
  166. .SH
  167. Responds To
  168. .Rs ifTrue:
  169. Return the result of evaluating the argument block.
  170. .Rs ifFalse:
  171. Return \fBnil\fP.
  172. .Rs ifTrue:ifFalse:
  173. Return the result of evaluating the first argument block.
  174. .Rs ifFalse:ifTrue:
  175. Return the result of evaluating the second argument block.
  176. .Rs not
  177. Return \fBfalse\fP.
  178. .Ex
  179. (3 < 5) not    False
  180. (3 < 5) ifTrue: [17]    17
  181. .Nm Object Boolean False
  182. .PP
  183. The pseudo variable \fBfalse\fP is an instance (usually the only instance) of
  184. the class \fBFalse\fP.
  185. .Rs ifTrue:
  186. Return \fBnil\fP.
  187. .Rs ifFalse:
  188. Return the result of evaluating the argument block.
  189. .Rs ifTrue:ifFalse:
  190. Return the result of evaluating the second argument block.
  191. .Rs ifFalse:ifTrue:
  192. Return the result of evaluating the first argument block.
  193. .Rs not
  194. Return \fBtrue\fP.
  195. .Ex
  196. (1 < 3) ifTrue: [17]    17
  197. (1 < 3) ifFalse: [17]    nil
  198. .Nm Object Magnitude
  199. .PP
  200. The class \fBMagnitude\fP provides protocol for those subclasses possessing
  201. a linear ordering.  For the sake of efficiency, most subclasses redefine
  202. some or all of the relational messages.  All methods are defined in
  203. terms of the basic messages <, = and >, which are in turn defined
  204. circularly in terms of each other.  Thus each subclass of \fBMagnitude\fP
  205. must redefine at least one of these messages.
  206. .Rs <
  207. Relational less than test.  Returns a boolean.
  208. .Rs <=
  209. Relational less than or equal test.
  210. .Rs =
  211. Relational equal test.  Note that this differs from ==, which is
  212. an object equality test.
  213. .Rs ~=
  214. Relational not equal test, opposite of =.
  215. .Rs >=
  216. Relational greater than or equal test.
  217. .Rs >
  218. Relational greater than test.
  219. .Rs between:and:
  220. Relational test for inclusion.
  221. .Rs max:
  222. Return the maximum of the receiver and argument value.
  223. .Rs min:
  224. Return the minimum of the receiver and argument value.
  225. .Ex
  226. $A max: $a    $a
  227. 4 between: 3.1 and: (17/3)    True
  228. .Nm Object Magnitude Char
  229. .PP
  230. This class defines protocol for objects with character values.
  231. Characters possess an ordering given by the underlying representation,
  232. however arithmetic is not defined for character values.
  233. Characters are written literally by preceding the character desired with
  234. a dollar sign, for example: $a \0 $B \0 $$.
  235. .SH
  236. Responds to
  237. .Rs == r
  238. Object equality test.  Two instances of the same character always test equal.
  239. .Rs asciiValue
  240. Return an \fBInteger\fP representing the ascii value of the receiver.
  241. .Rs asLowercase
  242. If the receiver is an uppercase letter returns the same letter in lowercase,
  243. otherwise returns the receiver.
  244. .Rs asUppercase
  245. If the receiver is a lowercase letter returns the same letter in uppercase,
  246. otherwise returns the receiver.
  247. .Rs asString r
  248. Return a length one string containing the receiver.
  249. Does not contain leading dollar sign, compare to \fIprintString\fP.
  250. .Rs digitValue
  251. If the receiver represents a number (for example $9) return the digit value
  252. of the number.  If the receiver is an uppercase letter (for example $B) return
  253. the position of the number in the uppercase letters + 10, ($B returns 11, for
  254. example).  If the receiver is neither a digit nor an uppercase letter an
  255. error is given and \fBnil\fP returned.
  256. .Rs isAlphaNumeric
  257. Respond true if receiver is either digit or letter, false otherwise.
  258. .Rs isDigit
  259. Respond true if receiver is a digit, false otherwise.
  260. .Rs isLetter
  261. Respond true if receiver is a letter, false otherwise.
  262. .Rs isLowercase
  263. Respond true if receiver is a lowercase letter, false otherwise.
  264. .Rs isSeparator
  265. Respond true if receiver is a space, tab or newline, false otherwise.
  266. .Rs isUppercase
  267. Respond true if receiver is an uppercase letter, false otherwise.
  268. .Rs isVowel
  269. Respond true if receiver is $a, $e, $i, $o or $u, in either
  270. upper or lower case.
  271. .Rs printString r    
  272. Respond with a string representation of the character value.
  273. Includes leading dollar sign, compare to \fIasString\fP, which does not include $.
  274. .Ex
  275. $A < $0    False
  276. $A asciiValue    65
  277. $A asString    A
  278. $A printString    $A
  279. $A isVowel    True
  280. $A digitValue    10
  281. .Nm Object Magnitude Number
  282. .PP
  283. The class \fBNumber\fP is an abstract superclass for \fBInteger\fP and \fBFloat\fP.
  284. Instances of \fBNumber\fP cannot be created directly.
  285. Relational messages and many arithmetic messages are redefined in each
  286. subclass for arguments of the appropriate type.  In general, an error message
  287. is given and \fBnil\fP returned for illegal arguments.
  288. .SH
  289. Responds To
  290. .Rs +
  291. Mixed type addition.
  292. .Rs \(mi
  293. Mixed type subtraction.
  294. .Rs *
  295. Mixed type multiplication
  296. .Rs /
  297. Mixed type division.
  298. .Rs \(ua n
  299. Exponentiation, same as raisedTo: .
  300. .Rs @
  301. Construct a point with coordinates being the receiver and the argument.
  302. .Rs abs
  303. Absolute value of the receiver.
  304. .Rs exp
  305. e raised to the power.
  306. .Rs gamma n
  307. Return the gamma function (generalized factorial) evaluated at the
  308. receiver.
  309. .Rs ln
  310. Natural logarithm of the receiver.
  311. .Rs log:
  312. Logarithm in the given base.
  313. .Rs negated
  314. The arithmetic inverse of the receiver.
  315. .Rs negative
  316. True if the receiver is negative.
  317. .Rs pi n
  318. Return the approximate value of the receiver multiplied by \*(p (3.1415926...).
  319. .Rs positive
  320. True if the receiver is positive.
  321. .Rs radians n
  322. Argument converted into radians.
  323. .Rs raisedTo:
  324. The receiver raised to the argument value.
  325. .Rs reciprocal
  326. The arithmetic reciprocal of the receiver.
  327. .Rs roundTo:
  328. The receiver rounded to units of the argument.
  329. .Rs sign
  330. Return \(mi1, 0 or 1 depending upon whether the receiver is negative, zero or
  331. positive.
  332. .Rs sqrt
  333. Square root.  nil if receiver is less than zero.
  334. .Rs squared
  335. Return the receiver multiplied by itself.
  336. .Rs strictlyPositive
  337. True if the receiver is greater than zero.
  338. .Rs to:
  339. Interval from receiver to argument value with step of 1.
  340. .Rs to:by:
  341. Interval from receiver to argument in given steps.
  342. .Rs truncatedTo:
  343. The receiver truncated to units of the argument.
  344. .Ex
  345. 3 < 4.1    True
  346. 3 + 4.1    7.1
  347. 3.14159 exp    23.1406
  348. 9 gamma    40320
  349. 5 reciprocal    0.2
  350. 0.5 radians    0.5 radians
  351. 13 roundTo: 5    15
  352. 13 truncateTo: 5    10
  353. .Nm Object Magnitude Number Integer
  354. .PP
  355. The class \fBInteger\fP provides protocol for objects with integer values.
  356. .SH
  357. Responds To
  358. .Rs == r
  359. Object equality test.  Two integers representing the same value are
  360. considered to be the same object.
  361. .Rs //
  362. Integer quotient, truncated towards negative infinity (compare to \fIquo:\fP).
  363. .Rs \e\e
  364. Integer remainder, truncated towards negative infinity (compare to \fIrem:\fP).
  365. .Rs allMask:
  366. Argument must be \fBInteger\fP.  Treating receiver and argument as bit strings,
  367. return \fBtrue\fP if all bits with 1 value in argument correspond to bits with 1
  368. values in the receiver.
  369. .Rs anyMask:
  370. Argument must be \fBInteger\fP.  Treating receiver and argument as bit strings,
  371. return true if any bit with 1 value in argument corresponds to a bit with
  372. 1 value in the receiver.
  373. .Rs asCharacter
  374. Return the Char with the same underlying ascii representation as the low
  375. order eight bits of the receiver.
  376. .Rs asFloat
  377. Floating point value with same magnitude as receiver.
  378. .Rs bitAnd:
  379. Argument must be \fBInteger\fP.  Treating the receiver and argument as bit strings,
  380. return logical \fBand\fP of values.
  381. .Rs bitAt:
  382. Argument must be \fBInteger\fP greater than 0 and less than underlying word size.
  383. Treating receiver as a bit string, return the bit value at the given position,
  384. numbering from low order (or rightmost) position.
  385. .Rs bitInvert
  386. Return the receiver with all bit positions inverted.
  387. .Rs bitOr:
  388. Return logical \fBor\fP of values.
  389. .Rs bitShift:
  390. Treating the receiver as a bit string, shift bit values by amount indicated
  391. in argument.  Negative values shift right, positive left.
  392. .Rs bitXor:
  393. Return logical \fBexclusive-or\fP of values.
  394. .Rs even
  395. Return true if receiver is even, false otherwise.
  396. .Rs factorial
  397. Return the factorial of the receiver.  Return as Float for large numbers.
  398. .Rs gcd:
  399. Argument must be \fBInteger\fP.  Return the greatest common divisor of the
  400. receiver and argument.
  401. .Rs highBit
  402. Return the location of the highest 1 bit in the receiver.
  403. Return \fBnil\fP for receiver zero.
  404. .Rs lcm:
  405. Argument must be \fBInteger\fP.  Return least common multiple of receiver and
  406. argument.
  407. .Rs noMask:
  408. Argument must be \fBInteger\fP.  Treating receiver and argument as bit strings,
  409. return true if no 1 bit in the argument corresponds to a 1 bit in the receiver.
  410. .Rs odd
  411. Return true if receiver is odd, false otherwise.
  412. .Rs quo:
  413. Return quotient of receiver divided by argument.
  414. .Rs radix:
  415. Return a string representation of the receiver value, printed in the base
  416. represented by the argument.  Argument value must be less than 36.
  417. .Rs rem:
  418. Remainder after receiver is divided by argument value.
  419. .Rs timesRepeat:
  420. Repeat argument block the number of times given by the receiver.
  421. .Ex
  422. 5 + 4    7
  423. 5 allMask: 4    True
  424. 4 allMask: 5    False
  425. 5 anyMask: 4    True
  426. 5 bitAnd: 3    1
  427. 5 bitOr: 3    7
  428. 5 bitInvert    \(mi6
  429. 254 radix: 16    16rFE
  430. \(mi5 // 4    \(mi2
  431. \(mi5 quo: 4    \(mi1
  432. \(mi5 \e\e 4    1
  433. \(mi5 rem: 4    \(mi1
  434. 8 factorial    40320
  435. .Nm Object Magnitude Number Float
  436. .PP
  437. The class \fBFloat\fP provides protocol for objects with floating point values.
  438. .SH
  439. Responds To
  440. .Rs == r
  441. Object equality test.  Return true if the receiver and argument
  442. represent the same floating point value.
  443. .Rs \(ua n
  444. Floating exponentiation.
  445. .Rs arcCos
  446. Return a \fBRadian\fP representing the arcCos of the receiver.
  447. .Rs arcSin
  448. Return a \fBRadian\fP representing the arcSin of the receiver.
  449. .Rs arcTan
  450. Return a \fBRadian\fP representing the arcTan of the receiver.
  451. .Rs  asFloat
  452. Return the receiver.
  453. .Rs ceiling
  454. Return the Integer ceiling of the receiver.
  455. .Rs coerce:
  456. Coerce the argument into being type Float.
  457. .Rs exp
  458. Return e raised to the receiver value.
  459. .Rs floor
  460. Return the Integer floor of the receiver.
  461. .Rs fractionPart
  462. Return the fractional part of the receiver.
  463. .Rs gamma n
  464. Return the value of the gamma function applied to the receiver value.
  465. .Rs integerPart
  466. Return the integer part of the receiver.
  467. .Rs ln
  468. Return the natural log of the receiver.
  469. .Rs radix:
  470. Return a string containing the printable representation of the receiver
  471. in the given radix.  Argument must be an Integer less than 36.
  472. .Rs rounded
  473. Return the receiver rounded to the nearest integer.
  474. .Rs sqrt
  475. Return the square root of the receiver.
  476. .Rs truncated
  477. Return the receiver truncated to the nearest integer.
  478. .Ex
  479. 4.2 * 3    12.6
  480. 2.1 \(ua 4    19.4481
  481. 2.1 raisedTo: 4    19.4481
  482. 0.5 arcSin    0.523599 radians
  483. 2.1 reciprocal    0.47619
  484. 4.3 sqrt    2.07364
  485. .Nm Object Magnitude Radian
  486. .PP
  487. The class \fBRadian\fP is used to represent radians.  Radians are a unit of
  488. measurement, independent of other numbers.
  489. Only radians will responds to the trigonometric functions
  490. such as \fIsin\fP and \fIcos\fP.
  491. Numbers can be converted into
  492. radians by passing them the message \fIradians\fP.  Similarly, radians
  493. can be converted into numbers by sending them the message \fIasFloat\fP.
  494. Notice that only a limited range of arithmetic operations are permitted on
  495. Radians.
  496. Radians are normalized to be between 0 and 2\(*p.
  497. .SH
  498. Responds to
  499. .Rs +
  500. Argument must be a Radian.  Add the two radians together and return the
  501. normalized result.
  502. .Rs \(mi
  503. Argument must be a Radian.  Subtract the argument from the receiver and
  504. return the normalized result.
  505. .Rs *
  506. Argument must be a Number.  Multiply the receiver by the argument amount
  507. and return the normalized result.
  508. .Rs /
  509. Argument must be a Number.  Divide the receiver by the argument amount
  510. and return the normalized result.
  511. .Rs asFloat
  512. Return the receiver as a floating point number.
  513. .Rs cos
  514. Return a floating point number representing the cosine of the
  515. receiver.
  516. .Rs sin
  517. Return a floating point number representing the sine of the receiver.
  518. .Rs tan
  519. Return a floating point number representing the tangent of the receiver.
  520. .Ex
  521. 0.5236 radians sin    0.5
  522. 0.5236 radians cos    0.866025
  523. 0.5236 radians tan    0.577352
  524. 0.5 arcSin asFloat    0.523599
  525. .Nm Object Magnitude Point
  526. .PP
  527. \fBPoint\fPs are used to represent pairs of quantities, such as coordinate
  528. pairs.
  529. .SH
  530. Responds To
  531. .Rs <
  532. True if both values of the receiver are less than the corresponding values
  533. in the argument.
  534. .Rs <=
  535. True if the first value is less than or equal to the corresponding value in
  536. the argument, and the second value is less than the corresponding value in
  537. the argument.
  538. .Rs >=
  539. True if both values of the receiver are greater than or equal to the
  540. corresponding values in the argument.
  541. .Rs *
  542. Return a new point with coordinates multiplied by the argument value.
  543. .Rs /
  544. Return a new point with coordinates divided by the argument value.
  545. .Rs //
  546. Return a new point with coordinates divided by the argument value.
  547. .Rs +
  548. Return a new point with coordinates offset by the corresponding values in
  549. the argument.
  550. .Rs abs
  551. Return a new point with coordinates having the absolute value of the
  552. receiver.
  553. .Rs dist:
  554. Return the Euclidean distance between the receiver and the argument
  555. point.
  556. .Rs max:
  557. The argument must be a \fBPoint\fP.
  558. Return the lower right corner of the rectangle defined by the receiver and
  559. the argument.
  560. .Rs min:
  561. The argument must be a \fBPoint\fP.
  562. Return the upper left corner of the rectangle defined by the receiver and
  563. the argument.
  564. .Rs transpose
  565. Return a new point with coordinates being the transpose of the receiver.
  566. .Rs x
  567. Return the first coordinate of the receiver.
  568. .Rs x:
  569. Set the first coordinate of the receiver.
  570. .Rs x:y:
  571. Sets both coordinates of the receiver.
  572. .Rs y
  573. Return the second coordinate of the receiver.
  574. .Rs y:
  575. Set the second coordinate of the receiver.
  576. .Ex
  577. (10@12) < (11@14)    True
  578. (10@12) < (11@11)    False
  579. (10@12) max: (11@11)    11@12
  580. (10@12) min: (11@11)    10@11
  581. (10@12) dist: (11@14)    2.23607
  582. (10@12) transpose    12@10
  583. .Nm Object Random
  584. .PP
  585. The class \fBRandom\fP provides protocol for random number generation.  Sending
  586. the message \fInext\fP to an instance of \fBRandom\fP results in a \fBFloat\fP
  587. between 0.0 and 1.0, randomly distributed.
  588. By default, the pseudo random sequence is the same for each object in class
  589. \fBRandom\fP.  This can be altered using the message \fIrandomize\fP.
  590. .SH
  591. Responds To
  592. .Rs between:and: n
  593. Return a random number uniformly distributed between the two arguments.
  594. .Rs first n
  595. Return a random number between 0.0 and 1.0.
  596. This message merely provides consistency with protocol for other sequences,
  597. such as Arrays or Intervals.
  598. .Rs next
  599. Return a random number between 0.0 and 1.0.
  600. .Rs next: d
  601. Return an \fBArray\fP containing the next n random numbers, where n
  602. is the argument value.
  603. .Rs randInteger: n
  604. The argument must be an integer.  Return a random integer between 1 and the
  605. value given.
  606. .Rs randomize n
  607. Change the pseudo-random number generator seed by a time dependent value.
  608. .Ex
  609. i \(<- Random new
  610. i next    0.759
  611. i next    0.157
  612. i next: 3    #( 0.408 0.278 0.547 )
  613. i randInteger: 12    5
  614. i between: 4 and: 17.5    10.0
  615. .Nm Object Collection
  616. .PP
  617. The class \fBCollection\fP provides protocol for groups of objects, such as
  618. \fBArray\fPs or \fBSet\fPs.
  619. The different forms of collections are distinguished by several
  620. characteristics, among them whether the size of the collection is fixed
  621. or unbounded, the presence or absence of an ordering, and their insertion
  622. or access method.  For example, an \fBArray\fP is a collection with a
  623. fixed size and ordering, indexed by integer keys.  A \fBDictionary\fP, on the
  624. other hand, has no fixed size or ordering, and can be indexed by
  625. arbitrary elements.  Nevertheless, \fBArrays\fP and \fBDictionarys\fP share many
  626. features in common, such as their access method (\fIat:\fP and \fPat:put:\fP),
  627. and the ability to respond to \fIcollect:\fP, \fIselect:\fP, and many other
  628. messages.
  629. .PP
  630. The table below lists some of the characteristics of several forms of
  631. collections:
  632. .TS
  633. center box;
  634. l c c c c c.
  635.  
  636. Name    Creation    Size    Ordered?    Insertion    Access
  637.     Method    fixed?        method    method
  638.  
  639. _
  640.  
  641. Bag/Set    new    no    no    add:    includes:
  642.  
  643. Dictionary    new    no    no    at:put:    at:
  644.  
  645. Interval    n to: m    yes    yes    none    at:
  646.  
  647. List    new    no    yes    addFirst:    first
  648.                 addLast:    last
  649.  
  650. Array    new:    yes    yes    at:put:    at:
  651.  
  652. String    new:    yes    yes    at:put:    at:
  653.  
  654. .TE
  655. .PP
  656. The list below shows messages that are shared in common by all collections.
  657. .SH
  658. Responds to
  659. .Rs addAll:
  660. The argument must be a \fBCollection\fP.
  661. Add all the elements of the argument collection to the receiver collection.
  662. .Rs asArray
  663. Return a new collection of type \fBArray\fP containing the elements from
  664. the receiver collection.  If the receiver was ordered, the elements will
  665. be in the same order in the new collection, otherwise the elements will
  666. be in an arbitrary order.
  667. .Rs asBag
  668. Return a new collection of type \fBBag\fP containing the elements from
  669. the receiver collection.
  670. .Rs asList n
  671. Return a new collection of type \fBList\fP containing the elements from
  672. the receiver collection.  If the receiver was ordered, the elements will
  673. be in the same order in the new collection, otherwise the elements will
  674. be in an arbitrary order.
  675. .Rs asSet
  676. Return a new collection of type \fBSet\fP containing the elements from
  677. the receiver collection.
  678. .Rs asString
  679. Return a new collection of type \fBString\fP containing the elements from the
  680. receiver collection.  The elements to be included must all be of type
  681. \fBCharacter\fP.  If the receiver was ordered, the elements will be in the same
  682. order in the new collection, otherwise the elements will be listed in an
  683. arbitrary order.
  684. .Rs coerce:
  685. The argument must be a collection.
  686. Return a collection, of the same type as the receiver, containing elements
  687. from the argument collection.  This message is redefined in most subclasses
  688. of collection.
  689. .Rs collect:
  690. The argument must be a one argument block.
  691. Return a new collection, like the receiver, containing the result of
  692. evaluating the argument block on each element of the receiver collection.
  693. .Rs detect:
  694. The argument must be a one argument block.
  695. Return the first element in the receiver collection for which the
  696. argument block evaluates true.  Report an error and return \fBnil\fP if
  697. no such element exists.
  698. Note that in unordered collections (such as \fBBags\fP or \fBDictionarys\fP) the first
  699. element to be encountered that will satisfy the condition may not be
  700. easily predictable.
  701. .Rs detect:ifAbsent:
  702. Return the first element in the receiver collection for which the
  703. first argument block evaluates true.  Return the result of evaluating
  704. the second argument if no such element exists.
  705. .Rs do:
  706. The argument must be a one argument block.
  707. Evaluate the argument block on each element in the receiver collection.
  708. .Rs includes:
  709. Return true if the receiver collection contains the argument.
  710. .Rs inject:into:
  711. The first argument must be a value, the second a two argument block.
  712. The second argument is evaluated once for each element in the receiver
  713. collection, passing as arguments the result of the previous evaluation
  714. (starting with the first argument) and the element.
  715. The value returned is the final value generated.
  716. .Rs isEmpty
  717. Return true if the receiver collection contains no elements.
  718. .Rs occurrencesOf:
  719. Return the number of times the argument occurs in the receiver collection.
  720. .Rs remove:
  721. Remove the argument from the receiver collection.  Report an error
  722. if the element is not contained in the receiver collection.
  723. .Rs remove:ifAbsent:
  724. Remove the first argument from the receiver collection.  Evaluate the second
  725. argument if not present.
  726. .Rs reject:
  727. The argument must be a one argument block.
  728. Return a new collection like the receiver containing all elements for
  729. which the argument block returns false.
  730. .Rs select:
  731. The argument must be a one argument block.
  732. Return a new collection like the receiver containing all elements for
  733. which the argument block returns true.
  734. .Rs size
  735. Return the number of elements in the receiver collection.
  736. .Ex
  737. i \(<- 'abacadabra'
  738. i size    10
  739. i asArray    #( $a $b $a $c $a $d $a $b $r $a )
  740. i asBag    Bag ( $a $a $a $a $a $r $b $b $c $d)
  741. i asSet    Set ( $a $r $b $c $d )
  742. i occurrencesOf: $a    5
  743. i reject: [:x | x isVowel]    bcdbr
  744. .Nm Object Collection Bag/Set
  745. .PP
  746. \fBBags\fP and \fBSets\fP are each
  747. unordered collections of elements.
  748. Elements in the collections do not have keys, but are added and removed
  749. directly.
  750. The difference between a \fBBag\fP and a \fBSet\fP is that each element can occur
  751. any number of times in a \fBBag\fP, whereas only one copy is inserted into
  752. a \fBSet\fP.
  753. .SH
  754. Responds to
  755. .Rs add:
  756. Add the indicated element to the receiver collection.
  757. .Rs add:withOccurences:
  758. (\fBBag\fP only) Add the indicated element to the receiver \fBBag\fP the given number
  759. of times.
  760. .Rs first n
  761. Return the first element from the receiver collection.
  762. As the collection is unordered, the first element
  763. depends upon certain values in the internal representation, and is
  764. not guaranteed to be any specific element in the collection.
  765. .Rs next n
  766. Return the next element in the collection.
  767. In conjunction with \fIfirst\fP, this can be used to access each
  768. element of the collection in turn.
  769. .Ex
  770. i \(<- (1 to: 6) asBag    Bag ( 1 2 3 4 5 6 )
  771. i size    6
  772. i select: [:x | (x \e\e 2) strictlyPositive]    Bag ( 1 3 5 )
  773. i collect: [:x | x \e\e 3]    Bag ( 0 0 1 1 2 2 )
  774. j \(<- ( i collect: [:x | x \e\e 3] ) asSet    Set ( 0 1 2 )
  775. j size    3
  776. .LP
  777. \fBNote:\fP Since \fBBags\fP and \fBSets\fP are unordered, there is no way to
  778. establish a mapping between the elements of the Bag i in the example above
  779. and the corresponding elements in the collection that resulted from the
  780. message collect: [:x | x \e\e 3].
  781. .Nm Object Collection KeyedCollection
  782. .PP
  783. The class \fBKeyedCollection\fP provides protocol for collections with keys,
  784. such as \fBDictionarys\fP and \fBArrays\fP.
  785. Since each entry in the collection has both a key and value, the
  786. method \fIadd:\fP is no longer appropriate.  Instead, the method
  787. \fIat:put:\fP, which provides both a key and a value, must be used.
  788. .SH
  789. Responds to
  790. .Rs asDictionary
  791. Return a new collection of type \fBDictionary\fP containing the elements
  792. from the receiver collection.
  793. .Rs at:
  794. Return the item in the receiver collection whose key matches the argument.
  795. Produces and error message, and returns nil, if no item is currently in
  796. the receiver collection under the given key.
  797. .Rs at:ifAbsent:
  798. Return the element stored in the dictionary under the key given by the
  799. first argument.  Return the result of evaluating the second argument if
  800. no such element exists.
  801. .Rs atAll:put:
  802. The first argument must be a collection containing keys valid for the
  803. receiver.  At each location given by a key in the first argument place
  804. the second argument.
  805. .Rs binaryDo:
  806. The argument must be a two argument block.  This message is similar to \fIdo:\fP,
  807. however both the key and the element value are passed as argument to the
  808. block.
  809. .Rs includesKey:
  810. Return true if the indicated key is valid for the receiver collection.
  811. .Rs indexOf:
  812. Return the key value of the first element in the receiver collection matching
  813. the argument.
  814. Produces an error message if no such element exists.
  815. Note that, as with the message \fIdetect:\fP, in unordered collections the
  816. first element may not be related in any way to the order in which elements
  817. were placed into the collection, but is rather implementation dependent.
  818. .Rs indexOf:ifAbsent:
  819. Return the key value of the first element in the receiver collection matching
  820. the argument.
  821. Return the result of evaluating the second argument if no such element
  822. exists.
  823. .Rs keys
  824. Return a Set containing the keys for the receiver collection.
  825. .Rs keysDo:
  826. The argument must be a one argument block.
  827. Similar to \fIdo:\fP, except that the values passed to the block are the keys
  828. of the receiver collection.
  829. .Rs keysSelect:
  830. Similar to \fIselect\fP, except that the selection is made on the basis of keys
  831. instead of values.
  832. .Rs removeKey:
  833. Remove the object with the given key from the receiver collection.
  834. Print an error message, and return \fBnil\fP, if no such object exists.
  835. Return the value of the deleted item.
  836. .Rs removeKey:ifAbsent:
  837. Remove the object with the given key from the receiver collection.
  838. Return the result of evaluating the second argument if no such object
  839. exists.
  840. .Rs values
  841. Return a Bag containing the values from the receiver collection.
  842. .Ex
  843. i \(<- 'abacadabra'
  844. i atAll: (1 to: 7 by: 2) put: $e    ebecedebra
  845. i indexOf: $r    9
  846. i atAll: i keys put: $z    zzzzzzzzzz
  847. i keys    Set ( 1 2 3 4 5 6 7 8 9 10 )
  848. i values    Bag ( $z $z $z $z $z $z $z $z $z $z )
  849. #(how odd) asDictionary    Dictionary ( 1 @ #how 2 @ odd )
  850. .Nm Object Collection KeyedCollection Dictionary
  851. .PP
  852. A \fBDictionary\fP is an unordered collection of elements, as are \fBBags\fP
  853. and \fBSets\fP.
  854. However, unlike these collections, elements inserted and removed from
  855. a \fBDictionary\fP must reference an explicit key.  Both the key and value
  856. portions of an element can be any object, although commonly the keys are
  857. instances of \fBSymbol\fP or \fBNumber\fP.
  858. .SH
  859. Responds to
  860. .Rs at:put:
  861. Place the second argument into the receiver collection under the key given
  862. by the first argument.
  863. .Rs currentKey
  864. Return the key of the last element yielded in response to a \fIfirst\fP or
  865. \fInext\fP request.
  866. .Rs first n
  867. Return the first element of the receiver collection.
  868. Return nil if the receiver collection is empty.
  869. .Rs next n
  870. Return the next element of the receiver collection, or nil if no such element
  871. exists.
  872. .Ex
  873. .ta 3i
  874. i \(<- Dictionary new
  875. i at: #abc put: #def
  876. i at: #pqr put: #tus
  877. i at: #xyz put: #wrt
  878. i print    Dictionary ( #abc @ #def #pqr @ #tus #xyz @ #wrt )
  879. i size    3
  880. i at: #pqr    #tus
  881. i indexOf: #tus    #pqr
  882. i keys    Set ( #abc #pqr #xyz )
  883. i values    Bag ( #wrt #def # tus )
  884. i collect: [:x | x asString at: 2]    Dictionary ( #abc @ $e #pqr @ $u #xyz @ $r)
  885. .Nm Object Collection KeyedCollection Dictionary Smalltalk
  886. .PP
  887. The class \fBSmalltalk\fP provides protocol for the pseudo variable
  888. \fBsmalltalk\fP.
  889. Since it is a subclass of Dictionary, this variable can be used to store
  890. information, and thus provide a means of communication between objects.
  891. Other messages modify various parameters used by the Little Smalltalk system.
  892. .SH
  893. Responds To
  894. .Rs date n
  895. Return the current date and time as a string.
  896. .Rs display n
  897. Set execution display to display the result of every expression typed, but
  898. not for assignments.
  899. Note that the display behavior can also be modified using the \-d argument
  900. on the command line.
  901. .Rs displayAssign n
  902. Set execution display to display the result of every expression typed,
  903. including assignment statements.
  904. .Rs doPrimitive:withArguments: n
  905. Execute the indicated primitive with arguments given by the second array.
  906. A few primitives (such as those dealing with process management) cannot be
  907. executed in this manner.
  908. .Rs noDisplay n
  909. Turn off execution display - no results will be displayed unless explicitly
  910. requested by the user.
  911. .Rs perform:withArguments: d
  912. Send indicated message to the receiver, using the arguments given.
  913. The first value in the argument array is taken to be the receiver of
  914. the message.
  915. Unpredictable results if the number of arguments is not appropriate for
  916. the given message.
  917. .Rs sh: n
  918. The argument, which must be a string, is executed as a Unix command by the
  919. shell.  The value returned is the termination status of the shell.
  920. .Rs time: n
  921. The argument must be a block.  The block is executed, and the number of
  922. seconds elapsed during execution returned.  Time is only accurate to within
  923. about one second.
  924. .Ex
  925. smalltalk date    Fri Apr 12 16:15:42 1985
  926. smalltalk perform: #+ withArguments: #(2 5)    7
  927. smalltalk doPrimitive: 10 withArguments: #(2 5)    7
  928. .Nm Object Collection KeyedCollection SequenceableCollection
  929. .PP
  930. The class \fBSequenceableCollection\fP contains protocol for collections that have
  931. a definite sequential ordering and are indexed by integer keys.
  932. Since there is a fixed order for elements, it is possible to refer to the
  933. last element in a \fBSequenceableCollection\fP.
  934. .SH
  935. Responds to
  936. .Rs ,
  937. Appends the argument collection to the receiver collection, returning a new
  938. collection of the same type as the receiver.
  939. .Rs copyFrom:to:
  940. Return a new collection, like the receiver, containing the designated
  941. subportion of the receiver collection.
  942. .Rs copyWith:
  943. Return a new collection, like the receiver, with the argument added to
  944. the end.
  945. .Rs copyWithout:
  946. Return a new collection, like the receiver, with all occurrences of
  947. the argument removed.
  948. .Rs equals:startingAt:
  949. The first argument must be a \fBSequenceableCollection\fP.
  950. Return true if each element of the receiver collection is equal to the
  951. corresponding element in the argument offset by the amount given in
  952. the second argument.
  953. .Rs findFirst:
  954. Find the key for the first element whose value satisfies the
  955. argument block.
  956. Produce an error message if no such element exists.
  957. .Rs findFirst:ifAbsent:
  958. Both arguments must be blocks.
  959. Find the key for the first element whose value satisfies the first argument block.
  960. If no such element exists return the value of the
  961. second argument.
  962. .Rs findLast:
  963. Find the key for the last element whose value satisfies the argument block.
  964. Produce an error message if no such element exists.
  965. .Rs findLast:ifAbsent:
  966. Both arguments must be blocks.
  967. Find the key for the last element whose value satisfies the first argument block.
  968. If no such element exists return the value of the second argument block.
  969. .Rs firstKey
  970. Return the first key valid for the receiver collection.
  971. .Rs indexOfSubCollection:startingAt:
  972. .br
  973. Starting at the position given by the second argument, find the next
  974. block of elements in the receiver collection which match the collection
  975. given by the first argument, and return the index for the start of that block.
  976. Produce an error message if no such position
  977. exists.
  978. .Rs indexOfSubCollection:startingAt:ifAbsent:
  979. .br
  980. Similar to \fIindexOfSubCollection:startingAt:\fP, except that the result of the
  981. exception block is produced if no position exists matching the pattern.
  982. .Rs last
  983. Return the last element in the receiver collection.
  984. .Rs lastKey
  985. Return the last key valid for the receiver collection.
  986. .Rs replaceFrom:to:with:
  987. Replace the elements in the receiver collection in the positions indicated
  988. by the first two arguments with values taken from the collection given
  989. by the third argument.
  990. .Rs replaceFrom:to:with:startingAt:
  991. .br
  992. Replace the elements in the receiver collection in the positions indicated
  993. by the first two arguments with values taken from the collection given
  994. in the third argument, starting at the position given by the fourth
  995. argument.
  996. .Rs reversed n
  997. Return a collection, like the receiver, with elements reversed.
  998. .Rs reverseDo:
  999. Similar to \fIdo\fP:, except that the items are presented in reverse order.
  1000. .Rs sort n
  1001. Return a collection, like the receiver, with the elements sorted
  1002. using the comparison <=.  Elements must be able to respond to the binary
  1003. message <=.
  1004. .Rs sort: n
  1005. The argument must be a two argument block which yields a boolean.
  1006. Return a collection, like the receiver, sorted using the argument
  1007. to compare elements for the purpose of ordering.
  1008. .Rs with:do:
  1009. The second argument must be a two argument block.
  1010. Present one element from the receiver collection and from the collection
  1011. given by the first argument in turn to the second argument block.
  1012. An error message is given if the collections do not have the same number of
  1013. elements.
  1014. .Ex
  1015. i \(<- 'abacadabra'
  1016. i copyFrom: 4 to: 8    cadab
  1017. i copyWith: $z    abacadabraz
  1018. i copyWithout: $a    bcdbr
  1019. i findFirst: [:x | x > $m]    9
  1020. i indexOfSubCollection: 'dab' startingAt: 1    6
  1021. i reversed    arbadacaba
  1022. i , i reversed    abacadabraarbadacaba
  1023. i sort: [:x :y | x >= y]    rdcbbaaaaa    
  1024. .Nm Object Collection KeyedCollection SequenceableCollection Interval
  1025. .PP
  1026. The class \fBInterval\fP represents a sequence of numbers in an arithmetic
  1027. sequence, either ascending or descending.  Instances of \fBInterval\fP are
  1028. created by numbers in response to the message \fIto:\fP or \fIto:by:\fP.
  1029. In conjunction with the message \fIdo:\fP, \fBIntervals\fP create a control
  1030. structure similar to do or for loops in Algol like languages.  For example:
  1031. .DS B
  1032. .sp
  1033. (1 to: 10) do: [:x | x print]
  1034. .sp
  1035. .DE
  1036. will print the numbers 1 through 10.
  1037. Although they are a collection, \fBIntervals\fP cannot be added to.
  1038. They can, however, be accessed randomly using the message \fIat\fP:.
  1039. .SH
  1040. Responds to
  1041. .Rs first
  1042. Produce the first element from the interval.  In conjunction with
  1043. \fIlast\fP, this message may be used to produce each element from the
  1044. interval in turn.  Note that \fBIntervals\fP also respond to the message
  1045. \fIat:\fP, which can be used to produce elements in an arbitrary order.
  1046. .Rs from:to:by:
  1047. Initialize the upper and lower bounds and the step size for the receiver.
  1048. (This is used principally internally by the method for number to create new
  1049. Intervals).
  1050. .Rs next
  1051. Produce the next element from the interval.
  1052. .Rs size
  1053. Return the number of elements that will be generated in producing the
  1054. interval.
  1055. .Ex
  1056. (7 to: 13 by: 3) asArray    #( 7 10 13 )
  1057. (7 to: 13 by: 3) at: 2    10
  1058. (1 to: 10) inject: 0 into: [:x :y | x + y]    55
  1059. (7 to: 13) copyFrom: 2 to: 5    #( 8 9 10 11 )
  1060. (3 to: 5) copyWith: 13    #( 3 4 5 13 )
  1061. (3 to: 5) copyWithout: 4    #( 3 5 )
  1062. (2 to: 4) equals: (1 to: 4) startingAt: 2    True
  1063. .Nm Object Collection KeyedCollection SequenceableCollection List
  1064. .PP
  1065. Lists represent collections with a fixed order, but indefinite
  1066. size.  No keys are used, and elements are added or removed from one end of
  1067. the other.
  1068. Used in this way, Lists
  1069. can perform as \fIstacks\fP or as \fIqueues\fP.  The table below
  1070. illustrates how stack and queue operations can be implemented in terms
  1071. of messages to instances of List.
  1072. .TS
  1073. center;
  1074. l s | l s
  1075. l l | l l.
  1076. \fIstack operations\fP    \fIqueue operations\fP
  1077.  
  1078. _
  1079. push    addLast:    add    addLast:    
  1080. pop    removeLast    first in queue    first    
  1081. top    last    remove first in queue    removeFirst
  1082. test empty    isEmpty    test empty    isEmpty
  1083. .TE
  1084. .SH
  1085. Responds to
  1086. .Rs add:
  1087. Add the element to the beginning of the receiver collection.  This is the same
  1088. as \fIaddFirst:\fP.
  1089. .Rs addAllFirst:
  1090. The argument must be a SequenceableCollection.  The elements of the argument
  1091. are added, in order, to the front of the receiver collection.
  1092. .Rs addAllLast:
  1093. The argument must be a SequenceableCollection.  The elements of the argument
  1094. are added, in order, to the end of the receiver collection.
  1095. .Rs addFirst:
  1096. The argument is added to the front of the receiver collection.
  1097. .Rs addLast:
  1098. The argument is added to the back of the receiver collection.
  1099. .Rs removeFirst
  1100. Remove the first element from the receiver collection, returning the
  1101. removed value.
  1102. .Rs removeLast
  1103. Remove the last element from the receiver collection, returning the
  1104. removed value.
  1105. .Ex
  1106. i \(<- List new
  1107. i addFirst: 2 / 3    List ( 0.6666 )
  1108. i add: $A    
  1109. i addAllLast: (12 to: 14 by: 2)
  1110. i print    List ( 0.6666 $A 12 14 )
  1111. i first    0.6666
  1112. i removeLast    14
  1113. i print    List ( 0.6666 $A 12 )
  1114. .Nm Object Collection KeyedCollection SequenceableCollection List Semaphore
  1115. .PP
  1116. Semaphores are used to synchronize concurrently running \fBProcesses\fP.
  1117. .SH
  1118. Responds To
  1119. .Rs new:
  1120. If created using \fInew\fP, a \fBSemaphore\fP starts out with zero excess
  1121. signals.  Alternatively, a \fBSemaphore\fP can be created with an arbitrary
  1122. number of excess signals by giving it an argument to \fInew\fP:.
  1123. .Rs signal
  1124. If there is a process blocked on the semaphore is it scheduled for
  1125. execution, otherwise
  1126. the number of excess signals is incremented by one.
  1127. .Rs wait
  1128. If there are excess signals associated with the semaphore the number of
  1129. signals is decremented by one, otherwise
  1130. the current process is placed on the semaphore queue.
  1131. .Nm Object Collection KeyedCollection SequenceableCollection File
  1132. .PP
  1133. A \fBFile\fP is a type of collection where the elements of the collection are
  1134. stored on an external medium, typically a disk.
  1135. For this reason, although most operations on collections are defined for
  1136. files, many can be quite slow in execution.
  1137. A file can be opened on one of three \fImodes\fP:
  1138. In \fIcharacter\fP mode every read returns a single character from the
  1139. file.
  1140. In \fIinteger\fP mode every read returns a single word, as an integer value.
  1141. In \fIstring\fP mode every read returns a single line, as a \fBString\fP.
  1142. For writing, character and string modes will write the string representation
  1143. of the argument, while integer mode must write only a single integer.
  1144. .SH
  1145. Responds To
  1146. .Rs at:
  1147. Return the object stored at the indicated position.  Position is given as a
  1148. character count from the start of the file.
  1149. .Rs at:put:
  1150. Place the object at the indicated position in the file.  Position is given
  1151. as a character count from the start of the file.
  1152. .Rs characterMode
  1153. Set the mode of the receiver file to \fIcharacter\fP.
  1154. .Rs currentKey
  1155. Return the current position in the file, as a character count from the
  1156. start of the file.
  1157. .Rs integerMode
  1158. Set the mode of the receiver file to \fIinteger\fP.
  1159. .Rs open:
  1160. Open the indicated file for reading.
  1161. The argument must be a \fBString\fP.
  1162. .Rs open:for:
  1163. The \fIfor:\fP argument must be one of 'r', 'w' or 'r+'
  1164. (see fopen(3) in the Unix programmers
  1165. manual).  Open the file in the indicated mode.
  1166. .Rs read
  1167. Return the next object from the file.
  1168. .Rs size
  1169. Return the size of the file, in character counts.
  1170. .Rs stringMode
  1171. Set the mode of the receiver file to \fIstring\fP.
  1172. .Rs write:
  1173. Write the argument into the file.
  1174. .Nm Object Collection KeyedCollection SequenceableCollection ArrayedCollection
  1175. .PP
  1176. The class \fBArrayedCollection\fP provides protocol for collections with a
  1177. Fixed size and integer keys.
  1178. Unlike other collections, which are created using the message \fInew\fP,
  1179. instances of \fBArrayedCollection\fP must be created using the one argument
  1180. message \fInew:\fP.  The argument given with this message must be a positive
  1181. integer, representing the size of the collection to be created.
  1182. In addition to the protocol shown, many of the methods inherited
  1183. from superclasses are redefined in this class.
  1184. .SH
  1185. Responds to
  1186. .Rs =
  1187. The argument must also be an \fBArray\fP.  Test whether the receiver and the
  1188. argument have equal elements listed in the same order.
  1189. .Rs at:ifAbsent:
  1190. Return the element stored with the given key.  Return the result
  1191. of evaluating the second argument if the key is not valid for the
  1192. receiver collection.
  1193. .Rs padTo: n
  1194. Return an array like the received that is at least as long as the argument
  1195. value.  Returns the receiver if it is already longer than the argument.
  1196. .Ex
  1197. \&'small' = 'small'    True
  1198. \&'small' = 'SMALL'    False
  1199. \&'small' asArray    #( $s $m $a $l $l)
  1200. \&'small' asArray = 'small'    True
  1201. #(1 2 3) padTo: 5    #(1 2 3 nil nil)
  1202. #(1 2 3) padTo: 2    #(1 2 3)
  1203. .Nm Object Collection KeyedCollection SequenceableCollection ArrayedCollection Array
  1204. .PP
  1205. Instances of the class \fBArray\fP are perhaps the most commonly used
  1206. data structure in Smalltalk programs.
  1207. \fBArrays\fP are represented textually by a pound sign preceding the list of
  1208. array elements.
  1209. .SH
  1210. Responds to
  1211. .Rs at:
  1212. Return the item stored in the position given by the argument.
  1213. An error message is produced, and \fBnil\fP returned, if the argument is not
  1214. a valid key.
  1215. .Rs at:put:
  1216. Store the second argument in the position given by the first argument.
  1217. An error message is produced, and \fBnil\fP returned, if the argument is not
  1218. a valid key.
  1219. .Rs grow:
  1220. Return a new array one element larger than the receiver, with the argument
  1221. value attached to the end.  This is a slightly more efficient command than
  1222. \fIcopyWith:\fP, although the effect is the same.
  1223. .Ex
  1224. i \(<- #(110 101 97)
  1225. i size    3
  1226. i \(<- i grow: 116    #( 110 101 97 116)
  1227. i \(<- i collect: [:x | x asCharacter]    #( #n #e #a #t )
  1228. i asString    neat
  1229. .Nm Object Collection KeyedCollection SequenceableCollection ArrayedCollection ByteArray
  1230. .PP
  1231. A \fBByteArray\fP is a special form of array in which the elements must be
  1232. numbers in the range 0-255.  Instances of \fBByteArray\fP are given a very
  1233. compact encoding, and are used extensively internally in the Little
  1234. Smalltalk system.
  1235. A \fBByteArray\fP can be represented textually by a pound sign preceding
  1236. the list of array elements surrounded by a pair of square braces.
  1237. .SH
  1238. Responds to
  1239. .Rs at:
  1240. Return the item stored in the position given by the argument.
  1241. An error message is produced, and \fBnil\fP returned, if the argument is not
  1242. a valid key.
  1243. .Rs at:put:
  1244. Store the second argument in the position given by the first argument.
  1245. An error message is produced, and \fBnil\fP returned, if the argument is not
  1246. a valid key.
  1247. .Ex
  1248. i \(<- #[110 101 97]
  1249. i size    3
  1250. i \(<- i copyWith: 116    #[ 110 101 97 116 ]
  1251. i \(<- i asArray collect: [:x | x asCharacter]    #( #n #e #a #t )
  1252. i asString    neat
  1253. .Nm Object Collection KeyedCollection SequenceableCollection ArrayedCollection String
  1254. .PP
  1255. Instances of the class \fBString\fP are similar to \fBArrays\fP, except
  1256. that the individual elements
  1257. must be \fBCharacter\fP.  \fBStrings\fP are represented literally by placing single
  1258. quote marks around the characters making up the string.
  1259. \fBStrings\fP also differ from \fBArrays\fP in that
  1260. Strings possess an ordering, given by the underlying ascii sequence.
  1261. .SH
  1262. Responds to
  1263. .Rs ,
  1264. Concatenates the argument to the
  1265. receiver string, producing a new string.
  1266. If the argument is not a \fBString\fP it is first converted
  1267. using \fIprintString\fP.
  1268. .Rs <
  1269. The argument must be a \fBString\fP.  Test if the receiver is lexically
  1270. less than the argument.  For the purposes of comparison case differences
  1271. are ignored.
  1272. .Rs <=
  1273. Test if the receiver is lexically less than or equal to the
  1274. argument.
  1275. .Rs >=
  1276. Test if the receiver is lexically greater than or equal to the argument.
  1277. .Rs >
  1278. Test if the receiver is lexically greater than the argument.
  1279. .Rs asSymbol r
  1280. Return a \fBSymbol\fP with characters given by the receiver string.
  1281. .Rs at:
  1282. Return the character stored at the position given by the argument.
  1283. Produce and error message, and return \fBnil\fP, if the argument does not represent
  1284. a valid key.
  1285. .Rs at:put:
  1286. Store the character given by second argument at the location given by
  1287. the first argument.  Produce an error message, and return \fBnil\fP, if either
  1288. argument is invalid.
  1289. .Rs copyFrom:length: n
  1290. Return a substring of the receiver.  The substring is taken from the
  1291. indicated starting position in the receiver and extends for the given length.
  1292. Produce an error message, and return \fBnil\fP, if the given positions are
  1293. not legal.
  1294. .Rs copyFrom:to: r
  1295. Return a substring of the receiver.  The substring is taken from the
  1296. indicated positions.
  1297. Produce an error message, and return \fBnil\fP, if the given positions are
  1298. not legal.
  1299. .Rs printAt: n
  1300. The argument must be a \fBPoint\fP which describes a location on the
  1301. terminal screen.  The string is printed at the specified location.
  1302. .Rs size
  1303. Return the number of characters stored in the string.
  1304. .Rs sameAs:
  1305. Return true if the receiver and argument string match with the exception of
  1306. case differences.  Note that the boolean message = , inherited from
  1307. ArrayedCollection, can be used to see if two strings are the same including
  1308. case differences.
  1309. .Ex
  1310. \&'example' at: 2    $x
  1311. \&'bead' at: 1 put: $r    read
  1312. \&'small' > 'BIG'    True
  1313. \&'small' sameAs: 'SMALL'    True
  1314. \&'tary' sort    arty
  1315. \&'Rats live on no evil Star' reversed    ratS live on no evil staR
  1316. .Nm Object Block
  1317. .PP
  1318. Although it is easy for the programmer to think of blocks as a syntactic
  1319. construct, or a control structure, they are actually objects, and share
  1320. attributes of all other objects in the Smalltalk system, such as the
  1321. ability to respond to messages.
  1322. .SH
  1323. Responds to
  1324. .Rs fork
  1325. Start the block executing as a \fBProcess\fP.
  1326. The value \fBnil\fP is immediately returned,
  1327. and the \fBProcess\fP created from the block
  1328. is scheduled to run in parallel with the current process.
  1329. .Rs forkWith:
  1330. Similar to \fIfork\fP, except that the array is passed as arguments to the
  1331. receiver block prior to scheduling for execution.
  1332. .Rs newProcess
  1333. A new \fBProcess\fP is created for the block, but is not
  1334. scheduled for execution.
  1335. .Rs newProcessWith: n
  1336. Similar to \fInewProcess\fP, except that the array is passed as arguments to the
  1337. receiver block prior to it being made into a process.
  1338. .Rs value
  1339. Evaluates the receiver block.  Produces an error message, and returns nil,
  1340. if the receiver block required arguments.  Return the value yielded by
  1341. the block.
  1342. .Rs value:
  1343. Evaluates the receiver block.  Produces an error message, and returns nil,
  1344. if the receiver block did not require a single argument.  Return the
  1345. value yielded by the block.
  1346. .Rs value:value:
  1347. Two argument block evaluation.
  1348. .Rs value:value:value:
  1349. Three argument block evaluation.
  1350. .Rs value:value:value:value:
  1351. Four argument block evaluation.
  1352. .Rs value:value:value:value:value:
  1353. .br
  1354. Five argument block evaluation.
  1355. .Rs whileTrue:
  1356. The receiver block is repeatedly evaluated.  While it evaluates to true,
  1357. the argument block is also evaluated.  Return nil when the receiver block
  1358. no longer evaluates to true.
  1359. .Rs whileTrue
  1360. The receiver block is repeatedly evaluated until it returns a value that is
  1361. not true.
  1362. .Rs whileFalse:
  1363. The receiver block is repeatedly evaluated.  While it evaluates to false,
  1364. the argument block is also evaluated.  Return nil when the receiver block
  1365. no longer evaluates to false.
  1366. .Rs whileFalse
  1367. The receiver block is repeatedly evaluated until it returns a value that is
  1368. not false.
  1369. .Ex
  1370. ['block indeed'] value    block indeed
  1371. [:x :y | x + y + 3] value: 5 value: 7    15
  1372. .Nm Object Class
  1373. .PP
  1374. The class \fBClass\fP provides protocol for manipulating class instances.
  1375. An instance of class \fBClass\fP is generated for each class in the Smalltalk
  1376. system.  New instances of this class are then formed by sending messages
  1377. to the class instance.
  1378. .SH
  1379. Responds to
  1380. .Rs deepCopy: n
  1381. The argument must be an instance of the receiver class.  A deepCopy
  1382. of the argument is returned.
  1383. .Rs edit n
  1384. The user is placed into a editor editing the file from which the class
  1385. description was originally obtained.  When the editor terminates, the class
  1386. description will be reparsed and will override the previous description.
  1387. See also \fIview\fP (below).
  1388. .Rs list n
  1389. Lists all subclasses of the given class recursively.
  1390. In particular, \fBObject\fP \fIlist\fP will list the names of all the
  1391. classes in the system.
  1392. .Rs new
  1393. A new instance of the receiver class is returned.  If the methods for
  1394. the receiver contain protocol for \fInew\fP, the new instance will
  1395. first be passed this message.
  1396. .Rs new:
  1397. A new instance of the receiver class is returned.  If the methods for
  1398. the receiver contain protocol for \fInew:\fP, the new instance will
  1399. first be passed this message.
  1400. .Rs respondsTo n
  1401. List all the messages that the current class will respond to.
  1402. .Rs respondsTo: d
  1403. The argument must be a Symbol.  Return true if the receiver class,
  1404. or any of its superclasses, contains a method
  1405. for the indicated message. Return false otherwise.
  1406. .Rs shallowCopy: n
  1407. The argument must be an instance of the receiver class.  A shallowCopy
  1408. of the argument is returned.
  1409. .Rs superClass n
  1410. Return the superclass of the receiver class.
  1411. .Rs variables n
  1412. Return an array containing the names of the instance variables used in
  1413. the receiver class.
  1414. .Rs view n
  1415. Place the user into an editor viewing the class description from which the
  1416. class was created.  Changes made to the file will not, however, affect the
  1417. current class representation.
  1418. .Ex
  1419. Array new: 3    #( nil nil nil )
  1420. Bag respondsTo: #add:    True
  1421. SequenceableCollection superClass    KeyedCollection
  1422. .Nm Object Process
  1423. .PP
  1424. Processes are created by the system, or by passing the message \fInewProcess\fP
  1425. or \fIfork\fP to a block; they cannot be created directly by the user.
  1426. .SH
  1427. Responds To
  1428. .Rs block
  1429. The receiver process is marked as being blocked.  This is usually
  1430. the result of a semaphore wait.
  1431. Blocked processes are not executed.
  1432. .Rs resume
  1433. If the receiver process has been \fIsuspend\fPed, it is rescheduled for
  1434. execution.
  1435. .Rs suspend
  1436. If the receiver process is scheduled for execution, it is marked as
  1437. suspended.  Suspended processes are not executed.
  1438. .Rs state
  1439. The current state of the receiver process is returned as a Symbol.
  1440. .Rs terminate
  1441. The receiver process is terminated.  Unlike a blocked or suspended process,
  1442. a terminated process cannot be restarted.
  1443. .Rs unblock
  1444. If the receiver process is currently blocked, it is scheduled for
  1445. execution.
  1446. .Rs yield
  1447. Returns \fBnil\fP.  As a side effect, however,
  1448. if there are pending processes the current process is
  1449. placed back on the process queue and another process started.
  1450.